package com.lxl.testHd.wc.one;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author ：e_lixilin
 * @date ：2022/2/21 10:30
 * @description：
 * @modified By：
 */
public class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    Text outKey = new Text();
    IntWritable outValue = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 行号, 本行的内容
        String line = value.toString();
        if (StringUtils.isNotBlank(line)) {
            String[] arr = line.split("\t");
            for (String word : arr) {
                outKey.set(word);
                outValue.set(1);
                context.write(outKey,outValue);
            }
        }
    }
}
